<?php
/*
 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
 * Copyright (C) 2002-2012 The Nucleus Group
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * (see nucleus/documentation/index.html#license for more info)
 */
/**
 * Functions to create lists of things inside the admin are
 *
 * @license http://nucleuscms.org/license.txt GNU General Public License
 * @copyright Copyright (C) 2002-2012 The Nucleus Group
 * @version $Id: skinableShowlist.php 163 2012-02-13 04:17:40Z shizuki17xx $

 */


// can take either an array of objects, or an SQL query
function skinableShowlist($query, $type, $template, $templateName = '')
{
    if (is_array($query)) {
        if (sizeof($query) == 0)
            return 0;

        call_user_func('skinableListplug_' . $type, $template, 'HEAD', $templateName);

        foreach ($query as $currentObj) {
            $template['current'] = $currentObj;
            call_user_func('skinableListplug_' . $type, $template, 'BODY', $templateName);
        }

        call_user_func('skinableListplug_' . $type, $template, 'FOOT', $templateName);

        return sizeof($query);

    } else {
        $res = sql_query($query);

        // don't do anything if there are no results
        $numrows = sql_num_rows($res);
        if ($numrows == 0)
            return 0;

        call_user_func('skinableListplug_' . $type, $template, 'HEAD', $templateName);

        while($template['current'] = sql_fetch_object($res))
            call_user_func('skinableListplug_' . $type, $template, 'BODY', $templateName);

        call_user_func('skinableListplug_' . $type, $template, 'FOOT', $templateName);

        sql_free_result($res);

        // return amount of results
        return $numrows;
    }
}

function skinableListplug_select($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_SELECT_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_SELECT_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_SELECT_HEAD'];
            } else {
                $template = "<select<%name%><%tabindex%><%javascript%>>\n<%extraoption%>\n";
            }
            $data = array(
                'name'        => isset($vars['name'])        ? ' name="' . $vars['name'] . '"'         : '',
                'tabindex'    => isset($vars['tabindex'])    ? ' tabindex="' . $vars['tabindex'] . '"' : '',
                'javascript'  => isset($vars['javascript'])  ? ' ' . $vars['javascript']               : '',
            );
            $data ['extraoption'] = isset($vars['extra']) ?
                '<option value="' . $vars['extra'] . '">' . $vars['extra'] . "</option>" :
                '';
//            echo '<select name="' . ifset($template['name']) . '" tabindex="' . ifset($template['tabindex']) . '" ' . ifset($template['javascript']) . '>';
            // add extra row if needed
//            if (ifset($template['extra'])) {
//                echo '<option value="', ifset($template['extraval']), '">', $template['extra'], '</option>';
//            }
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_SELECT_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_SELECT_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_SELECT_BODY'];
            } else {
                $template = '<option value="<%value%>"<%selected%><%title%>><%option%></option>' . "\n";
            }
            $data = array(
                'value'    => htmlspecialchars($current->value, ENT_QUOTES),
                'selected' => ($vars['selected'] == $current->value) ? ' selected="selected"' : '',
            );
            if (isset($vars['shorten']) && $vars['shorten'] > 0) {
                $data['title'] = ' title="' . htmlspecialchars($current->text, ENT_QUOTES) . '"';
                $current->text = shorten($current->text, $vars['shorten'], $vars['shortenel']);
            } else {
                $data['title'] = '';
            }
            $data['option'] = htmlspecialchars($current->text, ENT_QUOTES);

//            echo '<option value="' . htmlspecialchars($current->value) . '"';
//            if ($template['selected'] == $current->value)
//                echo ' selected="selected" ';

//            if (isset($template['shorten']) && $template['shorten'] > 0) {
//                echo ' title="'. htmlspecialchars($current->text).'"';
//                $current->text = shorten($current->text, $template['shorten'], $template['shortenel']);
//            }
//            echo '>' . htmlspecialchars($current->text) . '</option>';
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_SELECT_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_SELECT_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_SELECT_FOOT'];
            } else {
                $template = "</select>\n";
            }
            $data = array();
//            echo '</select>';
            break;
    }
    $template = skinableTEMPLATE::fill($template, $data);
    $handler  = new skinableACTIONS('template', $template, $data);
    $parser   = new PARSER(skinableACTIONS::getDefinedActions(), $handler);
    $parser->parse($template);
}

function skinableListplug_table($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_HEAD'];
            } else {
                $template = "<table><thead><tr>\n"
                          . "<%typehead%>\n"
                          . "</tr></thead><tbody>\n";
            }
            $data = array(
                'typehead' => call_user_func("skinableListplug_table_" . $vars['content'] , $vars, 'HEAD', $templateName)
            );
            break;
        case 'BODY':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_BODY'];
            } else {
                $template = '<tr onmouseover="focusRow(this);" onmouseout="blurRow(this);">'
                          . "<%typebody%>\n"
                          . "</tr>\n";
            }
            // print tabletype specific thingies
            $data = array(
                'typebody' => call_user_func("skinableListplug_table_" . $vars['content'] , $vars, 'BODY', $templateName)
            );
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_FOOT'];
            } else {
                $template = "<%typefoot%>\n"
                          . "</tbody></table>\n";
            }
            $data = array(
                'typefoot' => call_user_func("skinableListplug_table_" . $vars['content'] , $vars, 'FOOT', $templateName)
            );
            break;
    }
    $template = skinableTEMPLATE::fill($template, $data);
    $handler  = new skinableACTIONS('template', $template, $data);
    $parser   = new PARSER(skinableACTIONS::getDefinedActions(), $handler);
    $parser->parse($template);
}

function skinableListplug_table_memberlist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_HEAD'];
            } else {
                $template = "<th><%colmembername%></th>\n"
                          . "<th><%colmemberrname%></th>\n"
                          . "<th><%colmemberurl%></th>\n"
                          . "<th><%colmemberadmin%><%helplink(superadmin)%></th>\n"
                          . "<th><%colmemberlogin%><%helplink(canlogin)%></th>\n"
                          . "<th colspan=\"2\"><%colactions%></th>\n";
            }
            $data = array(
                'colmembername'  => _LIST_MEMBER_NAME,
                'colmemberrname' => _LIST_MEMBER_RNAME,
                'colmemberurl'   => _LIST_MEMBER_URL,
                'colmemberadmin' => _LIST_MEMBER_ADMIN,
                'colmemberlogin' => _LIST_MEMBER_LOGIN,
                'colactions'     => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_BODY'];
            } else {
                $template = "<td>\n"
                          . '<input type="checkbox" id="batch<%id%>" name="batch[<%id%>]" value="<%memberid%>" />' . "\n"
                          . '<label for=""batch<%id%>">' . "\n"
                          . '<a href="mailto:<%mailaddress%>" tabindex="<%tabindex%>"><%name%></a>' . "\n"
                          . "</label>\n"
                          . "</td>\n"
                          . "<td><%realname%></td>\n"
                          . '<td><a href="<%url%>" tabindex="<%tabindex%>"><%url%></a></td>' . "\n"
                          . "<td><%admin%></td>\n"
                          . "<td><%login%></td>\n"
                          . '<td><a href="index.php?action=memberedit&amp;memberid=<%memberid%>" tabindex="<%tabindex%>"><%editbtn%></a></td>' . "\n"
                          . '<td><a href="index.php?action=memberdelete&amp;memberid=<%memberid%>" tabindex="<%tabindex%>"><%deletebtn%></a></td>' . "\n";
            }
            $data = array(
                'id'          => skinableListplug_nextBatchId(),
                'memberid'    => $current->mnumber,
                'mailaddress' => htmlspecialchars($current->memail, ENT_QUOTES),
                'tabindex'    => $vars['tabindex'],
                'name'        => htmlspecialchars($current->mname, ENT_QUOTES),
                'realname'    => htmlspecialchars($current->mrealname, ENT_QUOTES),
                'url'         => htmlspecialchars($current->murl, ENT_QUOTES),
                'admin'       => ($current->madmin ? _YES : _NO),
                'login'       => ($current->mcanlogin ? _YES : _NO),
                'editbtn'     => _LISTS_EDIT,
                'deletebtn'   => _LISTS_DELETE,
            );

            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_MEMBLIST_FOOT'];
            } else {
                $template = "";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_teamlist($vars, $type, $templateName = '')
{
    global $manager;
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_HEAD'];
            } else {
                $template = "<th><%colmembername%></th>\n"
                          . "<th><%colmemberrname%></th>\n"
                          . "<th><%colteamadmin%><%helplink(teamadmin)%></th>\n"
                          . "<th colspan=\"2\"><%colactions%></th>\n";
            }
            $data = array(
                'colmembername'  => _LIST_MEMBER_NAME,
                'colmemberrname' => _LIST_MEMBER_RNAME,
                'colteamadmin'   => _LIST_TEAM_ADMIN,
                'colactions'     => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_BODY'];
            } else {
                $template = "<td>\n"
                          . '<input type="checkbox" id="batch<%id%>" name="batch[<%id%>]" value="<%memberid%>" />' . "\n"
                          . '<label for=""batch<%id%>">' . "\n"
                          . '<a href="mailto:<%mailaddress%>" tabindex="<%tabindex%>"><%name%></a>' . "\n"
                          . "</label>\n"
                          . "</td>\n"
                          . "<td><%realname%></td>\n"
                          . "<td><%admin%></td>\n"
                          . '<td><a href="index.php?action=teamdelete&amp;memberid=<%memberid%>&amp;blogid=<%blogid%>" tabindex="<%tabindex%>"><%deletebtn%></a></td>' . "\n"
                          . '<td><a href="<%chadminurl%>" tabindex="<%tabindex%>"><%chadminbtn%></a></td>' . "\n";
            }
            $url  = 'index.php?action=teamchangeadmin&memberid=' . intval($current->tmember) . '&blogid=' . intval($current->tblog);
            $url  = $manager->addTicketToUrl($url);
            $data = array(
                'id'          => skinableListplug_nextBatchId(),
                'memberid'    => $current->tmember,
                'mailaddress' => htmlspecialchars($current->memail, ENT_QUOTES),
                'tabindex'    => $vars['tabindex'],
                'name'        => htmlspecialchars($current->mname, ENT_QUOTES),
                'realname'    => htmlspecialchars($current->mrealname, ENT_QUOTES),
                'admin'       => ($current->tadmin ? _YES : _NO),
                'blogid'      => $current->tblog,
                'deletebtn'   => _LISTS_DELETE,
                'chadminurl'  => htmlspecialchars($url, ENT_QUOTES),
                'chadminbtn'  => _LIST_TEAM_CHADMIN,
            );
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_TEAMLIST_FOOT'];
            } else {
                $template = "";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_pluginlist($vars, $type, $templateName = '')
{
    global $manager;
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HEAD'];
            } else {
                $template = "<th><%colinfo%></th>\n"
                          . "<th><%coldesc%></th>\n"
                          . "<th style=\"white-space:nowrap\"><%colactions%></th>\n";
            }
            $data = array(
                'colinfo'    => _LISTS_INFO,
                'coldesc'    => _LISTS_DESC,
                'colactions' => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            $plug    =& $manager->getPlugin($current->pfile);
            $pid     = intval($current->pid);
            if ($plug) {
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY'])) {
                    $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_BODY'];
                } else {
                    $template = "<td>\n"
                              . "<strong><%plugname%></strong><br />\n"
                              . "<%autherlabel%> <%plugauther%><br />\n"
                              . "<%versionlabel%> <%plugversion%><br />\n"
                              . "<%pluggeturl%><br />\n"
                              . "</td>\n"
                              . "<td>\n"
                              . "<%desclabel%><br /><%plugdesc%>\n"
                              . "<%eventlist%>\n"
                              . "<%needupdate%>\n"
                              . "<%dependlist%>\n"
                              . "<%depreqlist%>\n"
                              . "</td>\n";
                }
                $data = array(
                    'plugname'     => htmlspecialchars($plug->getName(), ENT_QUOTES),
                    'autherlabel'  => _LIST_PLUGS_AUTHOR,
                    'plugauther'   => htmlspecialchars($plug->getAuthor(), ENT_QUOTES),
                    'versionlabel' => _LIST_PLUGS_VER,
                    'plugversion'  => htmlspecialchars($plug->getVersion(), ENT_QUOTES),
                    'tabindex'     => $vars['tabindex'],
                    'desclabel'    => _LIST_PLUGS_DESC,
                    'plugdesc'     => encode_desc($plug->getDescription()),
                );
                if ($plug->getURL()) {
                    if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL'])) {
                        $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_GURL'];
                    } else {
                        $subTpl = '<a href="<%plugurl%>" tabindex="<%tabindex%>"><%plugsite%></a>';
                    }
                    $subData = array(
                        'plugurl'  => htmlspecialchars($plug->getURL(), ENT_QUOTES),
                        'tabindex' => $vars['tabindex'],
                        'plugsite' => _LIST_PLUGS_SITE,
                    );
                    $data['pluggeturl'] = skinableTEMPLATE::fill($subTpl, $subData);
                } else {
                    $data['pluggeturl'] = '';
                }
                if (count($plug->getEventList()) > 0) {
                    if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST'])) {
                        $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGEVENTLIST'];
                    } else {
                        $subTpl = "<br /><br /><%evntlstlbl%><br /><%eventlist%>";
                    }
                    $subData = array(
                        'eventlist'  => htmlspecialchars(implode($plug->getEventList(), ', '), ENT_QUOTES),
                        'evntlstlbl' => _LIST_PLUGS_SUBS,
                    );
                    $data['eventlist'] = skinableTEMPLATE::fill($subTpl, $subData);
                } else {
                    $data['eventlist'] = '';
                }
                if (!$plug->subscribtionListIsUptodate()) {
                    if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE'])) {
                        $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGNEDUPDATE'];
                    } else {
                        $subTpl = "<br /><br /><strong><%updatealert%></strong>";
                    }
                    $subData = array(
                        'updatealert' => _LIST_PLUG_SUBS_NEEDUPDATE,
                    );
                    $data['needupdate'] = skinableTEMPLATE::fill($subTpl, $subData);
                } else {
                    $data['needupdate'] = '';
                }
                if (count($plug->getPluginDep()) > 0) {
                    if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND'])) {
                        $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPEND'];
                    } else {
                        $subTpl = "<br /><br /><%deplistlbl%><br /><%dependlist%>";
                    }
                    $subData = array(
                        'dependlist' => htmlspecialchars(implode($plug->getPluginDep(), ', '), ENT_QUOTES),
                        'deplistlbl' => _LIST_PLUGS_DEP,
                    );
                    $data['dependlist'] = skinableTEMPLATE::fill($subTpl, $subData);
                } else {
                    $data['dependlist'] = '';
                }
                $req = array();
                $res = sql_query('SELECT pfile FROM ' . sql_table('plugin'));
                while($o = sql_fetch_object($res)) {
                    $preq =& $manager->getPlugin($o->pfile);
                    if ($preq) {
                        $depList = $preq->getPluginDep();
                        foreach ($depList as $depName) {
                            if ($current->pfile == $depName) {
                                $req[] = $o->pfile;
                            }
                        }
                    }
                }
                if (count($req) > 0) {
                    if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ'])) {
                        $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGIN_DEPREQ'];
                    } else {
                        $subTpl = "<br /><br /><%deprlstlbl%><br /><%depreqlist%>";
                    }
                    $subData = array(
                        'dependlist' => htmlspecialchars(implode(', ', $req), ENT_QUOTES),
                        'deprlstlbl' => _LIST_PLUGS_DEPREQ,
                    );
                    $data['depreqlist'] = skinableTEMPLATE::fill($subTpl, $subData);
                } else {
                    $data['depreqlist'] = '';
                }
            } else {
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE'])) {
                    $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLISTFALSE'];
                } else {
                    $template = '<td colspan="2"><%noplugalert%></td>' . "\n";
                }
                $data = array(
                    'noplugalert' => sprintf(_PLUGINFILE_COULDNT_BELOADED, htmlspecialchars($current->pfile, ENT_QUOTES)),
                );
            }
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN'])) {
                $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ACTN'];
            } else {
                $template .= "<td>\n"
                          . '<a href="<%actionupurl%>" tabindex="<%tabindex%>"><%actionuptxt%></a><br />' . "\n"
                          . '<a href="<%actiondownurl%>" tabindex="<%tabindex%>"><%actiondowntxt%></a><br />' . "\n"
                          . '<a href="<%actuninsturl%>" tabindex="<%tabindex%>"><%actuninsttxt%></a><br />' . "\n"
                          . "<%plugadminurl%>\n"
                          . "<%plughelpurl%>\n"
                          . "<%plugoptsetting%>\n"
                          . "</td>\n";
            }
            $baseUrl = 'index.php?plugid=' . $pid . '&action=';
            $upUrl   = $manager->addTicketToUrl($baseUrl . 'pluginup');
            $downUrl = $manager->addTicketToUrl($baseUrl . 'plugindown');
            $data['actionuptxt']   = _LIST_PLUGS_UP;
            $data['actionupurl']   = htmlspecialchars($upUrl, ENT_QUOTES);
            $data['actiondowntxt'] = _LIST_PLUGS_DOWN;
            $data['actiondownurl'] = htmlspecialchars($downUrl, ENT_QUOTES);
            $data['actuninsttxt']  = _LIST_PLUGS_UNINSTALL;
            $data['actuninsturl']  = 'index.php?action=plugindelete&amp;plugid=' . $pid;
            if ($plug && ($plug->hasAdminArea() > 0)) {
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN'])) {
                    $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_ADMN'];
                } else {
                    $subTpl = '<a href="<%actadminurl%>" tabindex="<%tabindex%>"><%actadmintxt%></a><br />' . "\n";
                }
                $subData = array(
                    'actadminurl' => htmlspecialchars($plug->getAdminURL(), ENT_QUOTES),
                    'tabindex'    => $vars['tabindex'],
                    'actadmintxt' => _LIST_PLUGS_ADMIN,
                );
                $data['plugadminurl'] = skinableTEMPLATE::fill($subTpl, $subData);
            } else {
                $data['plugadminurl'] = '';
            }
            if ($plug && ($plug->hasAdminArea() > 0)) {
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP'])) {
                    $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_HELP'];
                } else {
                    $subTpl = '<a href="<%acthelpurl%>" tabindex="<%tabindex%>"><%acthelptxt%></a><br />' . "\n";
                }
                $subData = array(
                    'acthelpurl' => 'index.php?action=pluginhelp&amp;plugid=' . $pid,
                    'acthelptxt' => _LIST_PLUGS_HELP,
                    'tabindex'   => $vars['tabindex'],
                );
                $data['plughelpurl'] = skinableTEMPLATE::fill($subTpl, $subData);
            } else {
                $data['plughelpurl'] = '';
            }
            $optQuery = 'SELECT '
                      . '    COUNT(*) AS result '
                      . 'FROM '
                      .      sql_table('plugin_option_desc') . ' '
                      . 'WHERE '
                      . '    ocontext = "global" '
                      . 'AND opid     = %d';
            $pOptions = quickQuery(sprintf($optQuery, $pid));
            if ($pOptions > 0) {
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL'])) {
                    $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTSETURL'];
                } else {
                    $subTpl = '<a href="<%actoptionurl%>" tabindex="<%tabindex%>"><%actoptiontxt%></a>' . "\n";
                }
                $subData = array(
                    'actoptionurl' => 'index.php?action=pluginoptions&amp;plugid=' . $pid,
                    'actoptiontxt' => _LIST_PLUGS_OPTIONS,
                    'tabindex'     => $vars['tabindex'],
                );
                $data['plugoptsetting'] = skinableTEMPLATE::fill($subTpl, $subData);
            } else {
                $data['plugoptsetting'] = '';
            }
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_PLUGLIST_FOOT'];
            } else {
                $template = "";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_plugoptionlist($vars, $type, $templateName = '')
{
    global $manager;
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_HEAD'];
            } else {
                $template = "<th><%colinfo%></th><th><%colvalue%></th>\n";
            }
            $data = array(
                'colinfo'  => _LISTS_INFO,
                'colvalue' => _LISTS_VALUE,
            );
            break;
        case 'BODY':
            $current  = $vars['current'];
            $template = skinableListplug_plugOptionRow($current, $templateName);
            $data     = array();
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_FOOT'];
            } else {
                $template = "<tr>\n"
                          . '<th colspan="2"><%savetext%></th>' . "\n"
                          . "</tr><tr>\n<td><%savetext%></td>\n"
                          . '<td><input type="submit" value="<%savetext%>" /></td>' . "\n"
                          . "</tr>\n";
            }
            $data = array(
                'savetext' => _PLUGS_SAVE,
            );
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_plugOptionRow($current, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    $varname  = 'plugoption['.$current['oid'].']['.$current['contextid'].']';
    // retreive the optionmeta
    $metaData = NucleusPlugin::getOptionMeta($current['typeinfo']);
    // only if it is not a hidden option write the controls to the page
    if (isset($metaData['access']) && $metaData['access'] == 'hidden') {
        return false;
    } else {
        if (isset($templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY'])) {
            $template = $templates['SHOWLIST_LISTPLUG_TABLE_POPTLIST_BODY'];
        } else {
            $template = "<td><%description%></td>\n<td>\n";
        }
        $data = array();
        switch($current['type']) {
            case 'yesno':
                $template .= skinableACTIONS::input_yesno($varname, $current['value'], 0, 'yes', 'no', _YES, _NO, 0, $templateName, 1);
                break;
            case 'password':
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD'])) {
                    $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OPWORD'];
                } else {
                    $template .= '<input type="password" size="40" maxlength="128" name="<%varname%>" value="<%value%>" />' . "\n";
                }
                $data = array(
                    'varname' => htmlspecialchars($varname, ENT_QUOTES),
                    'value'   => htmlspecialchars($current['value'], ENT_QUOTES),
                );
                break;
            case 'select':
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP'])) {
                    $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEP'];
                } else {
                    $template .= '<select name="<%varname%>">' . "\n";
                }
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO'])) {
                    $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEO'];
                } else {
                    $subTpl = '<option value="<%value%>"<%selected%>><%optname%></option>' . "\n";
                }
                $aOptions = NucleusPlugin::getOptionSelectValues($current['typeinfo']);
                $aOptions = explode('|', $aOptions);
                for ($i=0; $i<(count($aOptions)-1); $i+=2) {
                    $subData = array(
                        'optname' => htmlspecialchars($aOptions[$i], ENT_QUOTES),
                        'value'   => htmlspecialchars($aOptions[$i+1], ENT_QUOTES),
                    );
                    if ($aOptions[$i+1] == $current['value']) {
                        $subData['selected'] = ' selected="selected"';
                    } else {
                        $subData['selected'] = '';
                    }
                    $template .= skinableTEMPLATE::fill($subTpl, $subData);
                }
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC'])) {
                    $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OSELEC'];
                } else {
                    $template .= '</select>' . "\n";
                }
                $data['varname'] = htmlspecialchars($varname, ENT_QUOTES);
                break;
            case 'textarea':
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA'])) {
                    $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OTAREA'];
                } else {
                    $template .= '<textarea class="pluginoption" cols="30" rows="5" name="<%varname%>"<%readonly%>><%value%></textarea>' . "\n";
                }
                $data = array(
                    'varname' => htmlspecialchars($varname, ENT_QUOTES),
                    'value'   => htmlspecialchars($current['value'], ENT_QUOTES),
                );
                if (isset($metaData['access']) && $metaData['access'] == 'readonly') {
                    $data['readonly'] = ' readonly="readonly"';
                } else {
                    $data['readonly'] = '';
                }
                break;
            case 'text':
            default:
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT'])) {
                    $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLGOPT_OITEXT'];
                } else {
                    $template .= '<input type="text" size="40" maxlength="128" name="<%varname%>" value="<%value%>"<%datatype%><%readonly%> />' . "\n";
                }
                $data = array(
                    'varname' => htmlspecialchars($varname, ENT_QUOTES),
                    'value'   => htmlspecialchars($current['value'], ENT_QUOTES),
                );
                if (isset($metaData['datatype']) && $metaData['datatype'] == 'numerical') {
                    $data['datatype'] = ' onkeyup="checkNumeric(this)" onblur="checkNumeric(this)"';
                } else {
                    $data['datatype'] = '';
                }
                if (isset($metaData['access']) && $metaData['access'] == 'readonly') {
                    $data['readonly'] = ' readonly="readonly"';
                } else {
                    $data['readonly'] = '';
                }
                break;
        }
        if (isset($templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT'])) {
            $template .= $templates['SHOWLIST_LISTPLUG_TABLE_PLUGOPTN_FOOT'];
        } else {
            $template .= "<%extra%></td>\n";
        }
        $data['extra']       = isset($current['extra']) ? $current['extra'] : '';
        $data['description'] = $current['description'] ? $current['description'] : $current['name'];
    }
    return skinableTEMPLATE::fill($template, $data, 1);
}

function skinableListplug_table_itemlist($vars, $type, $templateName = '')
{
    $cssclass  = null;
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }

    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_HEAD'];
            } else {
                $template = '<th><%colinfo%></th><th><%colcontent%></th><th style="white-space:nowrap"><%colaction%></th>' . "\n";
            }
            $data = array(
                'colinfo'    => _LIST_ITEM_INFO,
                'colcontent' => _LIST_ITEM_CONTENT,
                'colaction'  => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            $current->itime = strtotime($current->itime);   // string -> unix timestamp
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_BODY'];
            } else {
                $template = "<td<%cssclass%>>\n"
                          . "<%bshortlabel%> <%bshortnameval%><br />\n"
                          . "<%categorylabel%> <%categorynameval%><br />\n"
                          . "<%authorlabel%> <%authornameval%><br />\n"
                          . "<%itemdatelabel%> <%itemdateval%><br />\n"
                          . "<%itemtimelabel%> <%itemtimeval%>\n"
                          . "</td>\n"
                          . "<td<%cssclass%>>\n"
                          . '<input type="checkbox" id="batch<%batchid%>" name="batch<%batchid%>" value="<%itemid%>" />' . "\n"
                          . '<label for="batch<%batchid%>">' . "<b><%itemtitle%></b></label><br />\n"
                          . "<%itembody%></td>\n"
                          . '<td style="white-space:nowrap"<%cssclass%>>' . "\n"
                          . '<a href="index.php?action=itemedit&amp;itemid=<%itemid%>"><%editbtn%></a><br />' . "\n"
                          . "<%camount%>\n"
                          . '<a href="index.php?action=itemmove&amp;itemid=<%itemid%>"><%movebtn%></a><br />' . "\n"
                          . '<a href="index.php?action=itemdelete&amp;itemid=<%itemid%>"><%delbtn%></a>' . "\n"
                          . "</td>\n";
            }

            $cssclass = '';
            if ($current->idraft == 1) {
                $cssclass = ' class="draft"';
            }
            // (can't use offset time since offsets might vary between blogs)
            if ($current->itime > $vars['now']) {
                $cssclass = ' class="future"';
            }

            $body = strip_tags($current->ibody);
            $data = array(
                'cssclass'        => $cssclass,
                'bshortlabel'     => _LIST_ITEM_BLOG,
                'bshortnameval'   => htmlspecialchars($current->bshortname, ENT_QUOTES),
                'categorylabel'   => _LIST_ITEM_CAT,
                'categorynameval' => htmlspecialchars($current->cname, ENT_QUOTES),
                'authorlabel'     => _LIST_ITEM_AUTHOR,
                'authornameval'   => htmlspecialchars($current->mname, ENT_QUOTES),
                'itemdatelabel'   => _LIST_ITEM_DATE,
                'itemdateval'     => date("Y-m-d", $current->itime),
                'itemtimelabel'   => _LIST_ITEM_TIME,
                'itemtimeval'     => date("H:i", $current->itime),
                'batchid'         => skinableListplug_nextBatchId(),
                'itemid'          => $current->inumber,
                'itemtitle'       => htmlspecialchars(strip_tags($current->ititle), ENT_QUOTES),
                'itembody'        => htmlspecialchars(shorten($body, 300, '...'), ENT_QUOTES),
                'editbtn'         => _LISTS_EDIT,
                'movebtn'         => _LISTS_MOVE,
                'delbtn'          => _LISTS_DELETE,
            );
            $comment = new COMMENTS($current->inumber);
            $camount = $comment->amountComments();
            if ($camount > 0) {
                $data['camount'] = '<a href="index.php?action=itemcommentlist&amp;itemid="' . $current->inumber . '">'
                                 . '(' . sprintf(_LIST_ITEM_COMMENTS, $comment->amountComments()) . ")</a><br />\n";
            } else {
                $data['camount'] = _LIST_ITEM_NOCONTENT . "<br />\n";
            }

            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_ITEMLIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

// for batch operations: generates the index numbers for checkboxes
function skinableListplug_nextBatchId()
{
    static $id = 0;
    return $id++;
}

function skinableListplug_table_commentlist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_HEAD'];
            } else {
                $template = '<th><%colinfo%></th><th><%colcontent%></th><th colspan="3"><%colaction%></th>' . "\n";
            }
            $data = array(
                'colinfo'    => _LISTS_INFO,
                'colcontent' => _LIST_COMMENT,
                'colaction'  => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_BODY'];
            } else {
                $template = "<td><%commentdate%><br /><%commentator%><br /><%commentsite%><br /><%commentmail%><br /></td>\n"
                          . '<td><input type="checkbox" id="batch<%batchid%>" name="batch[<%batchid%>]" value="<%commentid%>" />'
                          . '<label for="batch<%batchid%>"><%commentbody%></label>' . "</td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=commentedit&amp;commentid=<%commentid%>"><%editbtn%></a>' . "</td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=commentdelete&amp;commentid=<%commentid%>"><%delbtn%></a>' . "</td>\n"
                          . "<%addbanlist%>";
            }
            $current = $vars['current'];
            $combody = strip_tags($current->cbody);
            $data    = array(
                'commentdate' => date("Y-m-d@H:i", strtotime($current->ctime)),
                'batchid'     => skinableListplug_nextBatchId(),
                'commentid'   => intval($current->cnumber),
                'commentbody' => htmlspecialchars(shorten($combody, 300, '...'), ENT_QUOTES),
                'editbtn'     => _LISTS_EDIT,
                'delbtn'      => _LISTS_DELETE,
            );
            if ($current->mname) {
                $data['commentator'] = htmlspecialchars($current->mname, ENT_QUOTES) . ' ' . _LIST_COMMENTS_MEMBER;
            } else {
                $data['commentator'] = htmlspecialchars($current->cuser, ENT_QUOTES);
            }
            if ($current->cmail != '') {
                $data['commentsite'] = htmlspecialchars($current->cmail, ENT_QUOTES);
            } else {
                $data['commentsite'] = '';
            }
            if ($current->cemail != '') {
                $data['commentmail'] = htmlspecialchars($current->cemail, ENT_QUOTES);
            } else {
                $data['commentmail'] = '';
            }

            if ($vars['canAddBan']) {
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN'])) {
                    $subTpl = $templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_ABAN'];
                } else {
                    $subTpl = '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=banlistnewfromitem&amp;itemid=<%itemid%>&amp;ip=<%banip%>" title="<%banhost%>"><%banbtn%></a>' . "</td>\n";
                }
                $subData = array(
                    'itemid'  => $current->citem,
                    'banip'   => htmlspecialchars($current->cip, ENT_QUOTES),
                    'banhost' => htmlspecialchars($current->chost, ENT_QUOTES),
                    'banbtn'  => _LIST_COMMENT_BANIP,
                );
                $data['addbanlist'] = skinableTEMPLATE::fill($subTpl, $subData);
            }
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_CMNTLIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}


function skinableListplug_table_bloglist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_HEAD'];
            } else {
                $template = '<th><%blognames%></th><th colspan="7"><%actionshead%></th>' . "\n";
            }
            $data = array(
                'blognames'   => _NAME,
                'actionshead' => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_BODY'];
            } else {
                $template = '<td title="blogid:<%blogid%> shortname:<%shortname%>">'."\n"
                          . '<a href="<%blogurl%>"><img src="images/globe.gif" width="13" height="13" alt="<%iconalt%>" /></a> <%blogname%>'."\n"
                          . "</td>\n"
                          . "<td>\n"
                          . '<a href="index.php?action=createitem&amp;blogid=<%blogid%>" title="<%ttaddtext%>"><%addtext%></a>'."\n"
                          . "</td>\n"
                          . "<td>\n"
                          . '<a href="index.php?action=itemlist&amp;blogid=<%blogid%>" title="<%ttedittext%>"><%edittext%></a>'."\n"
                          . "</td>\n"
                          . "<td>\n"
                          . '<a href="index.php?action=blogcommentlist&amp;blogid=<%blogid%>" title="<%ttcommenttext%>"><%commenttext%></a>'."\n"
                          . "</td>\n"
                          . "<td>\n"
                          . '<a href="index.php?action=bookmarklet&amp;blogid=<%blogid%>" title="<%ttbmlettext%>"><%bmlettext%></a>'."\n"
                          . "</td>\n";
            }
            $data = array(
                'blogid'        => $current->bnumber,
                'shortname'     => $current->bshortname,
                'blogurl'       => $current->burl,
                'iconalt'       => _BLOGLIST_TT_VISIT,
                'blogname'      => htmlspecialchars($current->bname, ENT_QUOTES),
                'ttaddtext'     => _BLOGLIST_TT_ADD,
                'addtext'       => _BLOGLIST_ADD,
                'ttedittext'    => _BLOGLIST_TT_EDIT,
                'edittext'      => _BLOGLIST_EDIT,
                'ttcommenttext' => _BLOGLIST_TT_COMMENTS,
                'commenttext'   => _BLOGLIST_COMMENTS,
                'ttbmlettext'   => _BLOGLIST_TT_BMLET,
                'bmlettext'     => _BLOGLIST_BMLET,
            );
            if ($current->tadmin == 1) {
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM'])) {
                    $template .= $templates['SHOWLIST_LISTPLUG_TABLE_BLIST_BD_TADM'];
                } else {
                    $template .= "<td>\n"
                               . '<a href="index.php?action=blogsettings&amp;blogid=<%blogid%>" title="<%ttsettingtext%>"><%settingtext%></a>'."\n"
                               . "</td>\n"
                               . "<td>\n"
                               . '<a href="index.php?action=banlist&amp;blogid=<%blogid%>" title="<%ttbanstext%>"><%banstext%></a>'."\n"
                               . "</td>\n";
                }
                $data['ttsettingtext'] = _BLOGLIST_TT_SETTINGS;
                $data['settingtext']   = _BLOGLIST_SETTINGS;
                $data['ttbanstext']    = _BLOGLIST_TT_BANS;
                $data['banstext']      = _BLOGLIST_BANS;
            }

            if ($vars['superadmin']) {
                if (isset($templates['SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM'])) {
                    $template .= $templates['SHOWLIST_LISTPLUG_TABLE_BLIST_BD_SADM'];
                } else {
                    $template .= "<td>\n"
                               . '<a href="index.php?action=deleteblog&amp;blogid=<%blogid%>" title="<%ttdeletetext%>"><%deletetext%></a>'."\n"
                               . "</td>\n";
                }
                $data['ttdeletetext'] = _BLOGLIST_TT_DELETE;
                $data['deletetext']   = _BLOGLIST_DELETE;
            }
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGLIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_shortblognames($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_HEAD'];
            } else {
                $template = "<th><%colshortname%></th><th><%colblogname%></th>\n";
            }
            $data = array(
                'colshortname' => _EBLOG_SHORTNAME,
                'colblogname'  => _EBLOG_NAME,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY'];
            } else {
                $template = "<td><%bshortname%></td><td><%blogname%></td>\n";
            }
            $data = array(
                'bshortname' => htmlspecialchars($current->bshortname, ENT_QUOTES),
                'blogname'   => htmlspecialchars($current->bname, ENT_QUOTES),
            );
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_shortnames($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_HEAD'];
            } else {
                $template = "<th><%colname%></th><th><%coldesc%></th>\n";
            }
            $data = array(
                'colname' => _NAME,
                'coldesc' => _LISTS_DESC,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_BLOGSNAM_BODY'];
            } else {
                $template = "<td><%name%></td><td><%desc%></td>\n";
            }
            $data = array(
                'name' => htmlspecialchars($current->name, ENT_QUOTES),
                'desc' => htmlspecialchars($current->description, ENT_QUOTES),
            );
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_SHORTNAM_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}


function skinableListplug_table_categorylist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_HEAD'];
            } else {
                $template = "<th><%colname%></th><th><%coldesc%></th>" . '<th colspan="2"><%colact%></th>' . "\n";
            }
            $data = array(
                'colname' => _LISTS_NAME,
                'coldesc' => _LISTS_DESC,
                'colact'  => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_BODY'];
            } else {
                $template = '<td><input type="checkbox" id="batch<%batchid%>" name="batch[<%batchid%>]" value="<%catid%>" />'
                          . '<label for="batch<%batchid%>"><%catname%></label>'
                          . "</td>\n"
                          . "<td><%catdesc%></td>\n"
                          . '<td><a href="index.php?action=categorydelete&amp;blogid=<%blogid%>&amp;catid=<%catid%>" tabindex="<%tabindex%>">'
                          . "<%delbtn%></a></td>\n"
                          . '<td><a href="index.php?action=categoryedit&amp;blogid=<%blogid%>&amp;catid=<%catid%>" tabindex="<%tabindex%>">'
                          . "<%editbtn%></a></td>\n";
            }
            $data = array(
                'batchid'  => skinableListplug_nextBatchId(),
                'catid'    => intval($current->catid),
                'catname'  => htmlspecialchars($current->cname, ENT_QUOTES),
                'catdesc'  => htmlspecialchars($current->cdesc, ENT_QUOTES),
                'blogid'   => intval($current->cblog),
                'tabindex' => $vars['tabindex'],
                'delbtn'   => _LISTS_DELETE,
                'editbtn'  => _LISTS_EDIT,
            );
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_CATELIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_templatelist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    global $manager;
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD'];
            } else {
                $template = "<th><%colname%></th><th><%coldesc%></th>" . '<th colspan="3"><%colact%></th>' . "\n";
            }
            $data = array(
                'colname' => _LISTS_NAME,
                'coldesc' => _LISTS_DESC,
                'colact'  => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY'];
            } else {
                $template = "<td><%templatename%></td>\n"
                          . "<td><%templatedesc%></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=templateedit&amp;templateid=<%templateid%>" tabindex="<%tabindex%>"><%editbtn%>'
                          . "</a></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="<%cloneurl%>" tabindex="<%tabindex%>"><%clonebtn%>'
                          . "</a></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=templatedelete&amp;templateid=<%templateid%>" tabindex="<%tabindex%>"><%delbtn%>'
                          . "</a></td>\n";
            }
            $url  = $manager->addTicketToUrl('index.php?action=templateclone&templateid=' . intval($current->tdnumber));
            $data = array(
                'templatename' => htmlspecialchars($current->tdname, ENT_QUOTES),
                'templatedesc' => htmlspecialchars($current->tddesc, ENT_QUOTES),
                'templateid'   => intval($current->tdnumber),
                'tabindex'     => $vars['tabindex'],
                'cloneurl'     => htmlspecialchars($url, ENT_QUOTES),
                'editbtn'      => _LISTS_EDIT,
                'clonebtn'     => _LISTS_CLONE,
                'delbtn'       => _LISTS_DELETE,
            );
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_skinlist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    global $CONF, $DIR_SKINS, $manager;
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD'];
            } else {
                $template = "<th><%colname%></th><th><%coldesc%></th>" . '<th colspan="3"><%colact%></th>' . "\n";
            }
            $data = array(
                'colname' => _LISTS_NAME,
                'coldesc' => _LISTS_DESC,
                'colact'  => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY'];
            } else {
                $template = "<td><%skinname%><br /><br />\n"
                          . "<%skintypelabel%> <%skintype%><br />\n"
                          . "<%incmodelabel%> <%incmode%><br />\n"
                          . "<%incpreflabel%> <%incpref%><br />\n"
                          . "<%skinthumb%>"
                          . "<%readme%></td>\n"
                          . '<td class="availableSkinTypes">' . "<%skindesc%><%skinparts%></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=skinedit&amp;skinid=<%skinid%>" tabindex="<%tabindex%>"><%editbtn%>'
                          . "</a></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="<%cloneurl%>" tabindex="<%tabindex%>"><%clonebtn%>'
                          . "</a></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=skindelete&amp;skinid=<%skinid%>" tabindex="<%tabindex%>"><%delbtn%>'
                          . "</a></td>\n";
            }
            $url  = $manager->addTicketToUrl('index.php?action=skinclone&skinid=' . intval($current->sdnumber));
            $data = array(
                'skintypelabel' => _LISTS_TYPE,
                'skintype'      => htmlspecialchars($current->sdtype, ENT_QUOTES),
                'incmodelabel'  => _LIST_SKINS_INCMODE,
                'incmode'       => ($current->sdincmode == 'skindir') ? _PARSER_INCMODE_SKINDIR : _PARSER_INCMODE_NORMAL,
                'incpreflabel'  => ($current->sdincpref) ? _LIST_SKINS_INCMODE : '',
                'incpref'       => ($current->sdincpref) ? htmlspecialchars($current->sdincpref, ENT_QUOTES) : '',
                'skindesc'      => htmlspecialchars($current->sddesc, ENT_QUOTES),
                'skinid'        => intval($current->sdnumber),
                'tabindex'      => $vars['tabindex'],
                'cloneurl'      => htmlspecialchars($url, ENT_QUOTES),
                'editbtn'       => _LISTS_EDIT,
                'clonebtn'      => _LISTS_CLONE,
                'delbtn'        => _LISTS_DELETE,
            );
            if ($current->sdnumber == $CONF['BaseSkin']) {
                $data['skinname'] = '<strong>' . htmlspecialchars($current->sdname, ENT_QUOTES) . '</strong>';
            } else {
                $data['skinname'] =  htmlspecialchars($current->sdname, ENT_QUOTES);
            }
            // add preview image when present
            if ($current->sdincpref && @file_exists($DIR_SKINS . $current->sdincpref . 'preview.png')) {
                $data['skinthumb'] = '<br /><br />';
                $hasEnlargement = @file_exists($DIR_SKINS . $current->sdincpref . 'preview-large.png');
                if ($hasEnlargement) {
                    $data['skinthumb'] .= '<a href="' . $CONF['SkinsURL'] . htmlspecialchars($current->sdincpref, ENT_QUOTES) . 'preview-large.png"'
                                        . ' title="' . _LIST_SKIN_PREVIEW_VIEWLARGER . '">';
                }
                $imgAlt = sprintf(_LIST_SKIN_PREVIEW, htmlspecialchars($current->sdname, ENT_QUOTES));
                $data['skinthumb'] .= '<img class="skinpreview" src="' . $CONF['SkinsURL'] . htmlspecialchars($current->sdincpref, ENT_QUOTES) . 'preview.png"'
                                    . ' width="100" height="75" alt="' . $imgAlt . '" />';
                if ($hasEnlargement) {
                    $data['skinthumb'] .= '</a>';
                }
            } else {
                $data['skinthumb'] = '';
            }
            if (@file_exists($DIR_SKINS . $current->sdincpref . 'readme.html')) {
                $url         = $CONF['SkinsURL'] . htmlspecialchars($current->sdincpref, ENT_QUOTES) . 'readme.html';
                $readmeTitle = sprintf(_LIST_SKIN_README, htmlspecialchars($current->sdname, ENT_QUOTES));
                $data['readme'] = '<br /><a href="' . $url . '" title="' . $readmeTitle . '">' . _LIST_SKIN_README_TXT . '</a>';
            } else {
                $data['readme'] = '';
            }
            $query = 'SELECT '
                   . '    stype '
                   . 'FROM '
                   .      sql_table('skin') . ' '
                   . 'WHERE '
                   . '    sdesc = ' . intval($current->sdnumber) . ' '
                   . 'ORDER BY '
                   . '    stype';
            $res   = sql_query($query);
            $types = array();
            while ($o = sql_fetch_object($res)) {
                $types[] = $o->stype;
            }
            if (count($types) > 0) {
                $friendlyNames = SKIN::getFriendlyNames();
                $defaultParts  = array(
                    'index',
                    'item',
                    'archivelist',
                    'archive',
                    'search',
                    'error',
                    'member',
                    'imagepopup'
                );
                for ($i=0;$i<count($types);$i++) {
                    $type = $types[$i];
                    if (in_array($type, $defaultParts)) {
                        $types[$i] = '<li>'
                                   . helpHtml('skinpart' . $type)
                                   . ' <a href="index.php?action=skinedittype&amp;skinid=' . $current->sdnumber . '&amp;type=' . $type . '" tabindex="' . $vars['tabindex'] . '">'
                                   . htmlspecialchars($friendlyNames[$type], ENT_QUOTES) . "</a></li>\n";
                    } else {
                        $types[$i] = '<li>'
                                   . helpHtml('skinpartspecial')
                                   . ' <a href="index.php?action=skinedittype&amp;skinid=' . $current->sdnumber . '&amp;type=' . $type . '" tabindex="' . $vars['tabindex'] . '">'
                                   . htmlspecialchars($friendlyNames[$type], ENT_QUOTES) . "</a></li>\n";
                    }
                }
                $data['skinparts'] = '<br /><br />' . _LIST_SKINS_DEFINED . "<ul>\n" . implode($types, '') . "</ul>\n";
            } else {
                $data['skinparts'] = '';
            }
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_draftlist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_HEAD'];
            } else {
                $template = "<th><%colblog%></th><th><%coldesc%></th>" . '<th colspan="2"><%colact%></th>' . "\n";
            }
            $data = array(
                'colblog' => _LISTS_BLOG,
                'coldesc' => _LISTS_TITLE,
                'colact'  => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $template['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_BODY'];
            } else {
                $template = "<td><%bshortname%></td>\n"
                          . "<td><%ititle%></td>\n"
                          . '<td><a href="index.php?action=itemedit&amp;itemid=<%itemid%>"><%editbtn%></a></td>' . "\n"
                          . '<td><a href="index.php?action=itemdelete&amp;itemid=<%itemid%>"><%delbtn%></a></td>' . "\n";
            }
            $data = array(
                'bshortname' => htmlspecialchars($current->bshortname),
                'ititle'     => htmlspecialchars($current->ititle),
                'itemid'     => htmlspecialchars($current->inumber),
                'editbtn'    => _LISTS_EDIT,
                'delbtn'     => _LISTS_DELETE,
            );
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_DRFTLIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}


function skinableListplug_table_actionlist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_HEAD'];
            } else {
                $template = "<th><%coltime%></th><th><%colmesg%></th>\n";
            }
            $data = array(
                'coltime' => _LISTS_TIME,
                'colmesg' => _LIST_ACTION_MSG,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_BODY'];
            } else {
                $template = "<td><%timestamp%></td><td><%message%></td>\n";
            }
            $data = array(
                'timestamp' => htmlspecialchars($current->timestamp, ENT_QUOTES),
                'message'   => htmlspecialchars($current->message, ENT_QUOTES),
            );
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_ACTNLIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_banlist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_HEAD'];
            } else {
                $template = "<th><%iprange%></th><th><%reason%></th><th><%colact%></th>\n";
            }
            $data = array(
                'iprange'=> _LIST_BAN_IPRANGE,
                'reason' => _LIST_BAN_REASON,
                'colact' => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_BODY'];
            } else {
                $template = "<td><%iprange%></td>\n"
                          . "<td><%reason%></td>\n"
                          . '<td><a href="index.php?action=banlistdelete&amp;blogid=<%blogid%>&amp;iprange=<%iprange%>"><%delbtn%></a></td>' . "\n";
            }
            $data = array(
                'iprange'=> htmlspecialchars($current->iprange, ENT_QUOTES),
                'reason' => htmlspecialchars($current->reason, ENT_QUOTES),
                'blogid' => intval($current->blogid),
                'delbtn' => _LISTS_DELETE,
            );
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_IBANLIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_adminskinlist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    global $CONF, $DIR_SKINS, $DIR_NUCLEUS, $manager;
//    $skinableAdmin = $manager->getPlugin('NP_SkinableAdmin');
    $adminSkinURL  = $CONF['AdminURL'] . 'adminskins/';
    $adminSkinDir  = $DIR_NUCLEUS . 'adminskins/';
//    $adminSkinURL  = $skinableAdmin->getAdminURL() . 'skinableadmin/adminskins/';
//    $adminSkinDir  = $skinableAdmin->getDirectory() . 'skinableadmin/adminskins/';
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_HEAD'];
            } else {
                $template = "<th><%colname%></th><th><%coldesc%></th>" . '<th colspan="3"><%colact%></th>' . "\n";
            }
            $data = array(
                'colname' => _LISTS_NAME,
                'coldesc' => _LISTS_DESC,
                'colact'  => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_BODY'];
            } else {
                $template = "<td><%skinname%><br /><br />\n"
                          . "<%skintypelabel%> <%skintype%><br />\n"
                          . "<%incmodelabel%> <%incmode%><br />\n"
                          . "<%incpreflabel%> <%incpref%><br />\n"
                          . "<%skinthumb%>"
                          . "<%readme%></td>\n"
                          . '<td class="availableSkinTypes">' . "<%skindesc%><%skinparts%></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=adminskinedit&amp;skinid=<%skinid%>" tabindex="<%tabindex%>"><%editbtn%>'
                          . "</a></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="<%cloneurl%>" tabindex="<%tabindex%>"><%clonebtn%>'
                          . "</a></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=adminskindelete&amp;skinid=<%skinid%>" tabindex="<%tabindex%>"><%delbtn%>'
                          . "</a></td>\n";
            }
            $url  = $manager->addTicketToUrl('index.php?action=adminskinclone&skinid=' . intval($current->sdnumber));
            $data = array(
                'skintypelabel' => _LISTS_TYPE,
                'skintype'      => htmlspecialchars($current->sdtype, ENT_QUOTES),
                'incmodelabel'  => _LIST_SKINS_INCMODE,
                'incmode'       => ($current->sdincmode == 'skindir') ? _PARSER_INCMODE_SKINDIR : _PARSER_INCMODE_NORMAL,
                'incpreflabel'  => ($current->sdincpref) ? _LIST_SKINS_INCMODE : '',
                'incpref'       => ($current->sdincpref) ? htmlspecialchars($current->sdincpref, ENT_QUOTES) : '',
                'skindesc'      => htmlspecialchars($current->sddesc, ENT_QUOTES),
                'skinid'        => intval($current->sdnumber),
                'tabindex'      => $vars['tabindex'],
                'cloneurl'      => htmlspecialchars($url, ENT_QUOTES),
                'editbtn'       => _LISTS_EDIT,
                'clonebtn'      => _LISTS_CLONE,
                'delbtn'        => _LISTS_DELETE,
            );
            if ($current->sdnumber == $CONF['DefaultAdminSkin']) {
                $data['skinname'] = '<strong>' . htmlspecialchars($current->sdname, ENT_QUOTES) . '</strong>';
            } else {
                $data['skinname'] =  htmlspecialchars($current->sdname, ENT_QUOTES);
            }
            // add preview image when present
            if ($current->sdincpref && @file_exists($adminSkinDir . $current->sdincpref . 'preview.png')) {
                $data['skinthumb'] = '<br /><br />';
                $hasEnlargement = @file_exists($adminSkinDir . $current->sdincpref . 'preview-large.png');
                if ($hasEnlargement) {
                    $data['skinthumb'] .= '<a href="' . $adminSkinURL . htmlspecialchars($current->sdincpref, ENT_QUOTES) . 'preview-large.png"'
                                        . ' title="' . _LIST_SKIN_PREVIEW_VIEWLARGER . '">';
                }
                $imgAlt = sprintf(_LIST_SKIN_PREVIEW, htmlspecialchars($current->sdname, ENT_QUOTES));
                $data['skinthumb'] .= '<img class="skinpreview" src="' . $adminSkinURL . htmlspecialchars($current->sdincpref, ENT_QUOTES) . 'preview.png"'
                                    . ' width="100" height="75" alt="' . $imgAlt . '" />';
                if ($hasEnlargement) {
                    $data['skinthumb'] .= '</a>';
                }
            } else {
                $data['skinthumb'] = '';
            }
            if (@file_exists($adminSkinDir . $current->sdincpref . 'readme.html')) {
                $url         = $adminSkinURL . htmlspecialchars($current->sdincpref, ENT_QUOTES) . 'readme.html';
                $readmeTitle = sprintf(_LIST_SKIN_README, htmlspecialchars($current->sdname, ENT_QUOTES));
                $data['readme'] = '<br /><a href="' . $url . '" title="' . $readmeTitle . '">' . _LIST_SKIN_README_TXT . '</a>';
            } else {
                $data['readme'] = '';
            }
            $query = 'SELECT '
                   . '    stype '
                   . 'FROM '
                   .      sql_table('adminskin') . ' '
                   . 'WHERE '
                   . '    sdesc = ' . intval($current->sdnumber) . ' '
                   . 'ORDER BY '
                   . '    stype';
            $res   = sql_query($query);
            $types = array();
            while ($o = sql_fetch_object($res)) {
                $types[] = $o->stype;
            }
            if (count($types) > 0) {
                    $adminDefaultTypes = skinableSKIN::getAdminskinDefaultTypes();
                    $friendlyNames     = skinableSKIN::getFriendlyNames();
                for ($i=0;$i<count($types);$i++) {
                    $type = $types[$i];
                    if (in_array($type, $adminDefaultTypes)) {
                        $types[$i] = '<li>'
                                   . helpHtml('skinpart' . $type)
                                   . ' <a href="index.php?action=adminskinedittype&amp;skinid=' . $current->sdnumber . '&amp;type=' . $type . '" tabindex="' . $vars['tabindex'] . '">'
                                   . htmlspecialchars($friendlyNames[$type], ENT_QUOTES) . "</a></li>\n";
                    } else {
                        $types[$i] = '<li>'
                                   . helpHtml('skinpartspecial')
                                   . ' <a href="index.php?action=adminskinedittype&amp;skinid=' . $current->sdnumber . '&amp;type=' . $type . '" tabindex="' . $vars['tabindex'] . '">'
                                   . htmlspecialchars($friendlyNames[$type], ENT_QUOTES) . "</a></li>\n";
                    }
                }
                $data['skinparts'] = '<br /><br />' . _LIST_SKINS_DEFINED . "<ul>\n" . implode($types, '') . "</ul>\n";
            } else {
                $data['skinparts'] = '';
            }
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_SKINLIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}

function skinableListplug_table_admintemplatelist($vars, $type, $templateName = '')
{
    $templates = array();
    if (!empty($templateName)) {
        $templates = skinableTEMPLATE::read($templateName);
    }
    global $manager;
    switch($type) {
        case 'HEAD':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_HEAD'];
            } else {
                $template = "<th><%colname%></th><th><%coldesc%></th>" . '<th colspan="3"><%colact%></th>' . "\n";
            }
            $data = array(
                'colname' => _LISTS_NAME,
                'coldesc' => _LISTS_DESC,
                'colact'  => _LISTS_ACTIONS,
            );
            break;
        case 'BODY':
            $current = $vars['current'];
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_BODY'];
            } else {
                $template = "<td><%templatename%></td>\n"
                          . "<td><%templatedesc%></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=admintemplateedit&amp;templateid=<%templateid%>" tabindex="<%tabindex%>"><%editbtn%>'
                          . "</a></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="<%cloneurl%>" tabindex="<%tabindex%>"><%clonebtn%>'
                          . "</a></td>\n"
                          . '<td style="white-space:nowrap">'
                          . '<a href="index.php?action=admintemplatedelete&amp;templateid=<%templateid%>" tabindex="<%tabindex%>"><%delbtn%>'
                          . "</a></td>\n";
            }
            $url  = $manager->addTicketToUrl('index.php?action=admintemplateclone&templateid=' . intval($current->tdnumber));
            $data = array(
                'templatename' => htmlspecialchars($current->tdname, ENT_QUOTES),
                'templatedesc' => htmlspecialchars($current->tddesc, ENT_QUOTES),
                'templateid'   => intval($current->tdnumber),
                'tabindex'     => $vars['tabindex'],
                'cloneurl'     => htmlspecialchars($url, ENT_QUOTES),
                'editbtn'      => _LISTS_EDIT,
                'clonebtn'     => _LISTS_CLONE,
                'delbtn'       => _LISTS_DELETE,
            );
            break;
        case 'FOOT':
            if (isset($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT']) || !empty($templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT'])) {
                $template = $templates['SHOWLIST_LISTPLUG_TABLE_TPLTLIST_FOOT'];
            } else {
                $template = "\n";
            }
            $data = array();
            break;
    }
    return skinableTEMPLATE::fill($template, $data);
}
